<?php
// php code required for report...
$reportsObj = new RM_Reports();

$dao = new RM_Units;
$units = $dao->getAll(new RM_Unit_Search_Criteria);

$reservationsModel = new RM_Reservations();

$jsonFields = array();

foreach ($units as $unit) {
    $reservationData = $reservationsModel->fetchAllByUnit($unit)->count();
    $jsonFields[] = array("label"=>$unit->name, "value"=>$reservationData);
}

$json = Zend_Json::encode($jsonFields);
?>
<b>Unit Rental Performance Pie Chart</b><br/>
<div id="rm_piechart_render_area">
    
</div>

<script type="text/javascript">

var piechartStore = new Ext.data.JsonStore({
    fields:[
        {name:'label', type:'string'},
        {name:'value', type:'int'}
    ],
    data : <?php echo $json;?>,
    autoLoad: true
});

new Ext.Panel({
    id: 'rm_reports_module_unit_performance_piechart',
    width: 800,
    height: 400,
    bodyBorder : false,
    renderTo: 'rm_piechart_render_area',
    items: [{
        store: piechartStore,
        xtype: 'piechart',
        dataField: 'value',
        categoryField: 'label',
        height: 400,
        width: 700,
        chartStyle: {
            animationEnabled: true
        },
        extraStyle:{
            legend:
            {
                display: 'right',
                padding: 5,
                font:
                {
                    family: 'Tahoma',
                    size: 11
                }
            }
        }
    }]
});

Ext.getCmp('rm_reports_run_button_print').disable();

</script>